package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.common.dto.StatsChartDto;
import com.cxx.home.dto.anniversary.AnniversaryDto;
import com.cxx.home.service.AnniversaryService;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/anniversary")
@Tag(name = "纪念日")
public class AnniversaryController {
    @Resource
    private AnniversaryService anniversaryService;

    @Operation(summary = "查询纪念日")
    @GetMapping("")
    public @JsonView(ReadView.class) List<AnniversaryDto> queryAnniversary(@RequestParam("category") String category) {
        return anniversaryService.queryAnniversary(category);
    }

    @Operation(summary = "新增纪念日")
    @PostMapping("")
    public Boolean addAnniversary(@RequestBody @JsonView(WriteView.class) @Validated AnniversaryDto anniversaryDto) {
        return anniversaryService.addAnniversary(anniversaryDto);
    }

    @Operation(summary = "更新纪念日")
    @PutMapping("/{id}")
    public Boolean updateAnniversary(@PathVariable("id") long id,
                                     @RequestBody @JsonView(WriteView.class) AnniversaryDto anniversaryDto) {
        return anniversaryService.updateAnniversary(id, anniversaryDto);
    }

    @Operation(summary = "删除纪念日")
    @DeleteMapping("/{id}")
    public Boolean deleteAnniversary(@PathVariable("id") long id) {
        return anniversaryService.deleteAnniversary(id);
    }

    @Operation(summary = "查询纪念日类别")
    @GetMapping("/category")
    public List<StatsChartDto> queryAnniversaryCategory() {
        return anniversaryService.queryAnniversaryCategory();
    }
}
    